class UnionFind():
    def __init__(self, num_node):
        self.num_node = num_node
        self.parent = [i for i in range(num_node+1)]
        
    def find(self, node):
        if self.parent[node] != node:
            self.parent[node] = self.find(self.parent[node])
        return self.parent[node]
    
    def union(self, s, t):
        parent_s = self.find(s)
        parent_t = self.find(t)
        if parent_t != parent_s:
            self.parent[parent_t] = parent_s
        
    def is_same(self, node1, node2):
        return self.find(node1) == self.find(node2)
    
    
def main():
    num_node = int(input())
    uf = UnionFind(num_node)
    
    for i in range(num_node):
        node1, node2 = map(int, input().split())
        if uf.is_same(node1, node2):
            print(f'{node1} {node2}')
            return 
        else:
            uf.union(node1, node2)
        

main()